<?php include('includes/start_session.php') ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
    <title>e-class course</title>
    <link href="styles/site.css" rel="stylesheet" type="text/css" />
    <link href="styles/zipped.css" rel="stylesheet" type="text/css" />

    <script src="scripts/scripts.js" type="text/javascript"></script>
</head>
<body onload="same_height()">
	<?php include('includes/header.php') ?>
	<div id="content">
		<?php
			include('db-api/txt-db-api.php');
		
			function ShowProfessors($id)
			{
				echo '<b>Διδάσκοντες: </b>';
					
				$db = new Database('Eclass');
				$rs = $db->executeQuery(
					'SELECT Users.Name, Users.Surname
					 FROM Users, ProfessorsCourses
					 WHERE ProfessorsCourses.CourseId = ' . $id . ' AND 
					 ProfessorsCourses.ProfessorName = Users.Username');
					 
				 $first = true;
				 while($rs->next())
				 {
				 	list($name, $surname) = $rs->getCurrentValues();
				 	if($first == false)
				 		echo ', ';
				 	echo $name . ' ' . $surname;
				 	$first = false;
				 }
					
				echo '</p>';
			}

		
			$db = new Database("Eclass");

			$found = false;
			if(isset($_GET['id']))
			{
				$rows = $db->executeQuery("SELECT Courses.*, CategoryName FROM Courses, SubCategories WHERE SubCategory = SubCategories.Name AND Courses.Id = " . $_GET['id']);
				$found = $rows->next();
			}
			
			if ($found == false)
			{
				echo '<h3>Το μάθημα δε βρέθηκε</h3>';
			}
			else
			{
				list($id, $name, $description, $subcat, $cat) = $rows->getCurrentValues();
				echo '<h3>' . $name . '</h3>';
				echo '<p>' . $description . '</p>';
				ShowProfessors($id);
				echo '<br /><b>Κατηγορία</b>: ' . $cat . '<br />';
				echo '<b>Υποκατηγορία</b>: ' . $subcat . '<br />';
				echo '<div class="right_align">';
				if(isset($_SESSION['previous_page']))
					echo '<a class="course_anchor" href="' . $_SESSION['previous_page'] . '">Επιστροφή</a>';
				else
					echo '<a class="course_anchor" href="javascript:history.back()">Επιστροφή</a>';
				echo '</div>';
				
				$showInactiveLinks = false;
				$showStudentLinks = false;
				if(isset($_SESSION['user']))
				{
					$rs = $db->executeQuery(
					'SELECT *
					 FROM ProfessorsCourses
					 WHERE ProfessorsCourses.ProfessorName = \'' . $_SESSION['username'] . '\' 
					 AND ProfessorsCourses.CourseId = ' . $id);
					 
					if($rs->next())
					{	
						 $showInactiveLinks = true;
					}
					else
					{
						 $showInactiveLinks = false;
					}
					
					$rs = $db->executeQuery(
					'SELECT *
					 FROM UsersCourses
					 WHERE UsersCourses.UserName = \'' . $_SESSION['username'] . '\' 
					 AND UsersCourses.CourseId = ' . $id);
					 
					if($rs->next())
					{		
						 $showStudentLinks = true;
					}
					else
					{
						 $showStudentLinks = false;
					}
				}
		?>
			<hr />
		
		
	<?php 
        function showAdminLinks()
		{
		 
			echo '<fieldset>';
					echo "<legend class=\"admin_legend\">Μόνο για Διαχειριστές</legend>";
					echo '<table class="stretched_table">';
						echo '<tr>';
							echo '<td>';
								echo '<div>';
									echo '<a class="course_anchor" href=\"#\">Αλλαγή τύπου πρόσβασης</a>';
								echo '</div>';
							echo '</td>';
							echo '<td>';
								echo '<div>';
									echo '<a class="course_anchor" href=\"#\">Προσθήκη Ιστοσελίδας</a>';
								echo '</div>';
							echo '</td>';
							echo '<td>';
								echo '<div>';
									echo '<a class="course_anchor" href=\"#\">Προσθήκη συνδέσμου στην αρχική σελίδα</a>';
								echo '</div>';
							echo '</td>';
						echo '</tr>';
							echo '<tr>';
							echo '<td>';
								echo '<div>';
									echo '<a class="course_anchor" href=\"#\">Στατιστικά</a>';
								echo '</div>';
							echo '</td>';
						echo '</tr>';
					echo '</table>';
				echo '</fieldset>';
		}
		?>
		<?php
		if(isset($_SESSION['user']))
		{
			if($_SESSION['position'] == 'Admin')
		   		showAdminLinks();
		
		}
		?>
		
		<?php
		if(isset($_SESSION['user']))
		{ 
		   	if($showStudentLinks == true || $showInactiveLinks == true)
		   	{
				echo '<fieldset>';
					if($showInactiveLinks == true)
						echo '<legend>Ενεργοποιημένοι σύνδεσμοι</legend>';
					else
						echo '<legend>Σύνδεσμοι μαθήματος</legend>';
					echo '<table class="stretched_table">';
						echo '<tr>';
							echo '<td>';
								echo '<div>';
									echo '<a class="course_anchor" href="agenda.php?id=' . $_GET['id'] . '">Αντζέντα</a>';
									echo '<br />';
									if($showInactiveLinks == true)
										echo '<a class="anchor_enable" href=\"#\">απενεργοποίηση</a>';
								echo '</div>';
							echo '</td>';
							echo '<td>';
								echo '<div>';
									echo '<a class="course_anchor" href=\"#\">Εργασίες μαθήματος</a>';
									echo '<br />';
									if($showInactiveLinks == true)
										echo '<a class="anchor_enable" href=\"#\">απενεργοποίηση</a>';
								echo '</div>';
							echo '</td>';
						echo '</tr>';
					echo '</table>';
				echo '</fieldset>';
			}
		}
		?> 
		

        <?php 
		if(isset($_SESSION['user']))
		{
		    if($showInactiveLinks == true)
				include('includes/inactive.php');
		}
	}
?>
        


			</div>
 
        <?php include('includes/footer.php') ?>
</body>
</html>

